<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.w3.org/1999/xhtml">
<head>
    <meta charset="UTF-8">
    <title>Title</title>

    <script src="/js/jquery-2.1.1.min.js"></script>
    <script src="/js/jquery-form.js"></script>

    <link rel="stylesheet" href="/js/easyui1.5/themes/icon.css">
    <link rel="stylesheet" href="/js/easyui1.5/themes/default/easyui.css">
    <script src="/js/easyui1.5/jquery.easyui.min.js"></script>


    <script type="text/javascript" th:inline="none">


        $(function () {
            queryLog();
        })

        function queryLog(){


            $("#dg").datagrid({

                url:'/mg/queryLog',
                striped:true,
                pagination:true,
                //  toolbar:"#gongneng",
                pageList:[1,2,3,4,5,7,10,50],
                pageSize:5,
                checkOnSelect:false,
                columns:[[
                    {field:'xxx',title:'xx',width:100,checkbox:true},
                    {field:'id',title:'id',width:100},
                    {field:'userAccout',title:'用户名',width:100},
                    {field:'addTime',title:'登录时间',width:100,
                        formatter:function(value,row,index){
                            var date=new Date(value+2880000)
                            var aa= date.toLocaleDateString(date)
                            return aa;
                        }},
                    {field:'name',title:'登录的主机名称',width:100},
                    {field:'version',title:'操作的系统',width:100},
                    {field:'phone',title:'手机号码',width:100},
                    {field:'xsxs',title:'操作',width:100,
                        formatter:function(value,row,index){

                            var content = " <a href='JavaScript:delLog(\""+row.id+"\")' >删除</a> ";

                            return content;
                        }
                    }
                ]]

            })
        }


        function setEvent(){

            var rows = $("#dg").datagrid("getChecked");
            var ids = "";
            $.each(rows,function(index,obj){
                ids += ids==""?obj.id:","+obj.id;
            });

            if(ids!=null&&ids!=""){
                   delLog(ids);
            }


        }


        function delLog(ids){

            $.ajax({
                url:"/mg/delLog",
                type:"get",
                data:{ids:ids},
                success:function(result){
                    queryLog();

                    $.messager.show({
                        title:'消息',
                        msg:'删除成功!!',
                        timeout:5000,
                        showType:'slide'
                    });

                },
                error:function(){
                    alert("失败了");
                }
            });


        }

        function poidaoChu(){

            var rows = $("#dg").datagrid("getChecked");
            var ids = "";
            $.each(rows,function(index,obj){
                ids += ids==""?obj.id:","+obj.id;
            });

            if(ids!=null&&ids!=""){
               location.href="/poi/queryMongo?ids="+ids;
            }

        }


        function importExcelTest() {

            var file = $('#FileUpload').filebox("getText");
            //判断文件上传是否为空
            if (file == null || file == "") {
                $.messager.alert('系统提示', '请选择将要上传的文件!');
                return;
            }
            //分割文件的类型
            var file_typename = file.substring(file.lastIndexOf('.'), file.length);
            if (file_typename == '.xlsx' || file_typename == '.xls') {
                var options = {
                    method: 'POST',
                    url: '/poi/importMongo',
                    data: file,
                    dataType: 'text',
                    success: function (data) {
                        if (data) {
                            queryLog();
                            $.messager.show({
                                title: '提示',
                                msg: '用户批量导入成功',
                                showType: 'slide'
                            })
                            $('#FileUpload').filebox("setText", "");

                        } else {
                            //$.messager.alert('警告', '导入异常，请检查是否正确使用模板！')
                            $.messager.alert('提示', data)
                        }
                    }
                }
                $('#testform').ajaxSubmit(options);
            } else {
                $.messager.alert('提示', '请选择正确的文件类型')
            }

        }

        function poiImport() {
            window.location.href = "/poi/exportExcel";
        }


    </script>
</head>
<body>
<div id="gongneng">
    <a href="JavaScript:void(0)" onclick="setEvent()" class="easyui-linkbutton" data-options="iconCls:'icon-cancel'"></a>
    <a href="JavaScript:void(0)" onclick="poidaoChu()" class="easyui-linkbutton" data-options="iconCls:'icon-undo'">批量导出</a>
    <a href="JavaScript:void(0)" onclick="poiImport()" class="easyui-linkbutton" data-options="iconCls:'icon-undo'">导出100万条数据</a>

    <form id="testform" enctype="multipart/form-data" >
        <input id="FileUpload" class="easyui-filebox"  name="file" data-options="prompt:'选择文件....'" />
        <a id="addExcel" class="easyui-linkbutton" data-options="iconCls:'icon-add'" onclick="importExcelTest()">上传</a>
    </form>
</div>
     <table id="dg"></table>
</body>
</html>